import os
import sys
import subprocess

def run_updater_bat(bat_path):
    """隐藏运行updater.bat"""
    try:
        if not os.path.exists(bat_path):
            raise Exception(f"bat文件不存在: {bat_path}")
        
        # 隐藏运行参数
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW
        startupinfo.wShowWindow = subprocess.SW_HIDE
        
        # 运行bat文件
        process = subprocess.Popen(
            ['cmd', '/c', bat_path],
            creationflags=subprocess.CREATE_NO_WINDOW,
            startupinfo=startupinfo
        )
        return True
    except Exception as e:
        print(f"运行updater.bat失败: {str(e)}")
        return False

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("用法: updater_plugin.py [bat文件路径]")
        sys.exit(1)
        
    success = run_updater_bat(sys.argv[1])
    sys.exit(0 if success else 1)